<template>
    <div class="game-all-data-box" v-loading="loading">
        <div class="input-box">
            <span class="input-title" style="margin-left:0px;">日期</span>
            <el-date-picker
                @change="getList(1)"
                v-model="date"
                :clearable="false"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:280px"
                :picker-options="pickerOptions">
            </el-date-picker>

            <span class="input-title">维度</span>
            <el-select
                @change="getList(1)"
                style="width:150px;"
                v-model="status">
                <el-option label="新用户留存" :value="1"></el-option>
                <el-option label="活跃用户留存" :value="2"></el-option>
            </el-select>

            <span class="input-title">邀请人ID</span>
            <el-input
                placeholder="根据邀请人ID查询"
                @keyup.enter.native="getList(1)"
                style="width:180px;"
                clearable
                v-model.trim="userId">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>

            <el-button type="primary" class="btn" @click="getList(1)">搜索</el-button>
        </div>

        <div class="check-box">
            <el-checkbox v-model="showLiucun">留存</el-checkbox>
            <el-checkbox v-model="showQidong">游戏启动</el-checkbox>
            <el-checkbox v-model="showXiaZaiYouXi">下载游戏</el-checkbox>
            <el-checkbox v-model="showGuanKanShiPin">观看视频</el-checkbox>
            <el-checkbox v-model="showQuanXian">开启权限</el-checkbox>
            <el-checkbox v-model="showRenZheng">实名认证</el-checkbox>
            <el-checkbox v-model="showWanJiaRenZheng">玩家认证</el-checkbox>
            <el-checkbox v-model="showQidongQi">自定义启动器</el-checkbox>
            <el-checkbox v-model="showChouJiang">抽奖</el-checkbox>
            <el-checkbox v-model="showTeam">组队</el-checkbox>
            <el-checkbox v-model="showRent">租号</el-checkbox>
        </div>

        <ul class="table-scroll-box">
            <li class="table-box">
                <div class="table-title-box">
                    <div class="table-title" style="flex:1;">时间</div>
                    <div class="table-title" style="flex:12;">
                        <div class="table-title" style="flex:none;width:210px;">备注</div>
                        <div class="table-title-children" v-if="status === 1">新增</div>
                        <div class="table-title-children" v-else>活跃</div>
                        <div class="table-title-children">1天后</div>
                        <div class="table-title-children">2天后</div>
                        <div class="table-title-children">3天后</div>
                        <div class="table-title-children">4天后</div>
                        <div class="table-title-children">5天后</div>
                        <div class="table-title-children">6天后</div>
                        <div class="table-title-children">7天后</div>
                        <div class="table-title-children">14天后</div>
                        <div class="table-title-children" style="border-right:none;">30天后</div>
                    </div>
                </div>
                <div class="table-content-scroll-box" @scroll="contentScroll">
                    <div class="table-content-box" v-for="(item, index) in list" :key="index">
                        <div class="table-content" style="flex:1;">{{item.date | timeInit}}</div>
                        <div class="table-content" style="flex:12;">
                            <div style="flex:1;">
                                <el-tooltip :disabled="disabledTip" v-if="showLiucun">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="text-align:center;">留存 / 留存占比</div>
                                    </div>
                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div>留存/留存占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.userKeepOneDataVoList" :key="_index">{{_item.count}}/{{_item.scale | percent}}</div>
                                        </div>
                                    </div>
                                </el-tooltip>

                                <el-tooltip :disabled="disabledTip" v-if="showQidong">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="margin-bottom:3px;text-align:center;">游戏启动数 / 人均启动次数</div>
                                        <div style="text-align:center;">启动人数 / 启动人数占比</div>
                                    </div>
                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div style="margin-bottom:4px;">游戏启动数/人均启动次数</div>
                                            <div>启动人数/启动人数占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.userStartGameVoList" :key="_index">
                                                <div style="margin-bottom:4px;">{{_item.gameStartCount || 0}}/{{_item.userAverageStartCount || 0}}</div>
                                                <div>{{_item.gameStartUserCount}}/{{_item.gameStartScale | percent}}</div>
                                            </div>
                                        </div>
                                    </div>
                                </el-tooltip>

                                <el-tooltip :disabled="disabledTip" v-if="showXiaZaiYouXi">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="margin-bottom:3px;text-align:center;">下载游戏数 / 人均下载游戏数</div>
                                        <div style="text-align:center;">下载人数 / 下载人数占比</div>
                                    </div>
                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div style="margin-bottom:4px;">下载游戏数/人均下载游戏数</div>
                                            <div>下载人数/下载人数占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.userDownloadGameVoList" :key="_index">
                                                <div style="margin-bottom:4px;">{{_item.downloadGameCount || 0}}/{{_item.averageDownloadGameCount || 0}}</div>
                                                <div>{{_item.downloadGameUserCount || 0}}/{{_item.downloadGameScale | percent}}</div>
                                            </div>
                                        </div>
                                    </div>
                                </el-tooltip>

                                <el-tooltip :disabled="disabledTip" v-if="showGuanKanShiPin">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="margin-bottom:3px;text-align:center;">看视频数 / 人均看视频数</div>
                                        <div style="text-align:center;">看视频人数 / 看视频人数占比</div>
                                    </div>

                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div style="margin-bottom:4px;">看视频数/人均看视频数</div>
                                            <div>看视频人数/看视频人数占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.userVideoDataVoList" :key="_index">
                                                <div style="margin-bottom:4px;">{{_item.watchVideoCount || 0}}/{{_item.averageWatchVideoCount || 0}}</div>
                                                <div>{{_item.watchVideoUserCount || 0}}/{{_item.watchVideoScale | percent}}</div>
                                            </div>
                                        </div>
                                    </div>
                                </el-tooltip>

                                <el-tooltip :disabled="disabledTip" v-if="showQuanXian">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="text-align:center;">玩家认证开权限人数</div>
                                        <div style="text-align:center;">奖励开权限人数 / 其它开权限人数</div>
                                        <div style="text-align:center;">开权限总人数 / 开权限总人数占比</div>
                                    </div>
                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div>玩家认证开权限人数</div>
                                            <div>奖励开权限人数/其它方式开权限人数</div>
                                            <div>开权限总人数/开权限总人数占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.userOpenAuthorityVoList" :key="_index">
                                                <div style="margin-bottom:4px;">{{_item.authAuthority || 0}}</div>
                                                <div style="margin-bottom:4px;">{{_item.awardAuthority || 0}}/{{_item.otherAuthority || 0}}</div>
                                                <div>{{_item.userOpenAuthorityCount || 0}}/{{_item.openAuthorityScale | percent}}</div>
                                            </div>
                                        </div>
                                    </div>
                                </el-tooltip>

                                <el-tooltip :disabled="disabledTip" v-if="showRenZheng">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="text-align:center;">实名认证总人数 / 实名认证总人数占比</div>
                                    </div>
                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div>实名认证总人数/实名认证总人数占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.usreCertificationVoList" :key="_index">{{_item.certificationCount || 0}}/{{_item.certificationScale | percent}}</div>
                                        </div>
                                    </div>
                                </el-tooltip>

                                <el-tooltip :disabled="disabledTip" v-if="showWanJiaRenZheng">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="text-align:center;">玩家认证总人数 / 玩家认证总人数占比</div>
                                    </div>
                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div>玩家认证总人数/玩家认证总人数占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.userOpenAuthorityVoList" :key="_index">{{_item.authCount || 0}}/{{_item.authCountScale | percent}}</div>
                                        </div>
                                    </div>
                                </el-tooltip>

                                <el-tooltip :disabled="disabledTip" v-if="showQidongQi">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="text-align:center;">自定义启动器人数 / 人均占比</div>
                                    </div>
                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div>自定义启动器人数/人均占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.userStartOwnEditorVoList" :key="_index">{{_item.startOwnEditorCount || 0}}/{{_item.startOwnEditorCountScale | percent}}</div>
                                        </div>
                                    </div>
                                </el-tooltip>

                                <el-tooltip :disabled="disabledTip" v-if="showChouJiang">
                                    <div slot="content">
                                        <div style="margin-bottom:3px;text-align:center;">{{item.date | timeInit}}</div>
                                        <div style="margin-bottom:3px;text-align:center;">抽奖数 / 人均参与抽奖次数</div>
                                        <div style="text-align:center;">参与抽奖人数 / 参与抽奖人数占比</div>
                                    </div>
                                    <div class="table-children">
                                        <div class="children-item-title" style="flex:none;width:210px;">
                                            <div style="margin-bottom:4px;">抽奖数/人均参与抽奖次数</div>
                                            <div>参与抽奖人数/参与抽奖人数占比</div>
                                        </div>
                                        <div class="children-item-content" style="flex:10">
                                            <div v-for="(_item, _index) in item.userActivityDataVoList" :key="_index">
                                                <div style="margin-bottom:4px;">{{_item.activityCount || 0}}/{{_item.userAverageJoinCount || 0}}</div>
                                                <div>{{_item.activityUserCount}}/{{_item.joinUserScale | percent}}</div>
                                            </div>
                                        </div>
                                    </div>
                                </el-tooltip>

                            </div>
                        </div>
                    </div>
                </div>
            </li>
        </ul>

        <!-- <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="[10, 30, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div> -->
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'
export default {
    data () {
        return {
            loading: false,
            disabledTip: false,
            list: [],
            pageNum: 1,
            total: 0,
            pickerOptions: {
                disabledDate (time) {
                    return time.getTime() > Date.now()
                }
            },
            status: 1,
            userId: '',
            showLiucun: true, // 显示留存
            showQidong: true, // 显示游戏启动数目
            showGuanKanShiPin: false, // 显示观看视频数
            showXiaZaiYouXi: false, // 显示下载游戏数
            showQuanXian: true, // 显示开启权限数
            showRenZheng: true, // 显示实名认证数
            showWanJiaRenZheng: true, // 显示玩家认证
            showQidongQi: false, // 显示自定义启动器
            showChouJiang: true, // 显示抽奖
            showTeam: true, // 显示组队
            showRent: true, // 显示租号
            checkedCities: [],
            date: [] // 时间
        }
    },
    activated () {
        this.status = Number(window.localStorage.getItem('_userDataWeidu')) || 1
        let start = formatDate(new Date(), 'YYYY-MM-DD')
        let end = formatDate(new Date().getTime() - 3600 * 1000 * 24 * 7, 'YYYY-MM-DD')
        this.date = [end, start]
        this.getList(1)
    },

    watch: {
        status (val) {
            window.localStorage.setItem('_userDataWeidu', val)
        }
    },

    methods: {
        async getList (num) {
            if (this.loading) return
            this.loading = true
            this.pageNum = num

            let params = {
                pageNum: this.pageNum,
                pageSize: 99999,
                status: this.status
            }
            if (this.userId) {
                params.userId = this.userId
            }
            if (this.date && this.date.length) {
                params.startTime = this.date[0]
                params.endTime = this.date[1]
            }
            let res = await this.$http.get('/game/selectUserAboutKeep', {
                params
            })
            if (res.code === '0') {
                this.list = res.data
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
            this.loading = false
        },

        // sizeChange (val) {
        //     this.pageSize = val
        //     this.getList(1)
        // },

        // pageChange (val) {
        //     this.getList(val)
        // },

        contentScroll () {
            clearTimeout(this.timerId)
            this.disabledTip = true
            this.timerId = setTimeout(() => {
                this.disabledTip = false
            }, 300)
        }
    },

    filters: {
        timeInit (val) {
            if (val) {
                return formatDate(val, 'YYYY-MM-DD')
            } else {
                return '-'
            }
        },

        percent (val) {
            if (val) {
                return parseInt(val * 100) + '%'
            } else {
                return '0%'
            }
        }
    }
}
</script>

<style lang="scss" scoped>
    .game-all-data-box {
        position: relative;
        top: 0;
        left: 0;
        height: 100%;
        overflow: hidden;
        .input-box {
            margin-top: 10px;
            font-size: 13px;
            font-weight: 500;
            .input-title {
                margin: 0 5px 0 10px;
            }
            .btn {
                margin-left: 10px;
            }
        }
        .check-box {
            margin-top: 10px;
            /deep/ .el-checkbox {
                margin-right: 20px;
            }
        }
        .table-scroll-box {
            width: 100%;
            overflow-x: auto;
            overflow-y: hidden;
            margin: 15px 0;
            border: 1px #EEE solid;
        }
        .table-box {
            min-width: 1200px;
            .table-title-box {
                // padding-right: 15px;
                min-width: 1200px;
                display: flex;
                align-items: center;
                background: #fafafa;
                border-bottom: 1px #EEE solid;
                .table-title {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    border-right: 1px #EEE solid;
                    font-size: 13px;
                    color: rgba(0, 0, 0, 0.7);
                    font-weight: 500;
                    padding: 15px 0;
                    height: 50px;
                    &:last-child {
                        border-right: none;
                    }
                    .table-title-children {
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        flex: 1;
                        border-right: 1px #EEE solid;
                        height: 50px;
                    }
                }
            }
            .table-content-scroll-box {
                max-height: calc(100vh - 295px);
                overflow-y: auto;
                overflow-x: hidden;
            }

            .table-content-box {
                min-width: 1200px;
                display: flex;
                align-items: center;
                border-bottom: 1px #EEE solid;
                &:hover {
                    background-color: rgba(186, 231, 255, .2);
                }
                .table-content {
                    color: rgba(0, 0, 0, .85);
                    height: 100%;
                    font-size: 12px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    // border-right: 1px #EEE solid;
                    .table-children {
                        &:hover {
                            font-weight: 700;
                            color: rgba(0, 0, 0, 1);
                            // background-color: rgba(186, 231, 255, .3);
                        }
                        &:last-child {
                            border-bottom: none;
                        }
                        outline: none;
                        border-bottom: 1px #EEE solid;
                        border-left: 1px #EEE solid;
                        display: flex;
                        .children-item-title {
                            padding: 5px 0;
                            border-right: 1px #EEE solid;
                            text-align: center;
                        }
                        .children-item-content {
                            display: flex;
                            > div {
                                text-align: center;
                                padding: 5px 0;
                                width: 10%;
                                border-right: 1px #EEE solid;
                                &:nth-child(1) {
                                    background-color: rgba(186, 231, 255, 1);
                                }
                                &:nth-child(2) {
                                    background-color: rgba(186, 231, 255, .8);
                                }
                                &:nth-child(3) {
                                    background-color: rgba(186, 231, 255, .6);
                                }
                                &:nth-child(4) {
                                    background-color: rgba(186, 231, 255, .4);
                                }
                                &:nth-child(5) {
                                    background-color: rgba(186, 231, 255, .35);
                                }
                                &:nth-child(6) {
                                    background-color: rgba(186, 231, 255, .3);
                                }
                                &:nth-child(7) {
                                    background-color: rgba(186, 231, 255, .25);
                                }
                                &:nth-child(8) {
                                    background-color: rgba(186, 231, 255, .15);
                                }
                                &:nth-child(9) {
                                    background-color: rgba(186, 231, 255, .1);
                                }
                                &:nth-child(10) {
                                    background-color: rgba(186, 231, 255, .1);
                                    border-right: none;
                                }
                            }
                        }
                    }
                }
            }
        }
        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
    }
</style>
